home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-06-14 | 11.2 KB | 256 lines | [TEXT/PJMM] |
- {The Project should have the following files in it: }
- { µRunTime.lib LSP This is for main Pascal runtime library}
- { Interface.lib LSP This is the Mac trap interfaces}
- { InitTheMenus.p This initializes the Menus.}
- { About Modal Dialog}
- { Options Window}
- { HandleTheMenus Handle the menu selections.}
- {Set RUN OPTIONS to use the resource file PREC4.RSRC }
- { RMaker file to use is PREC4.R }
- { PREC4.p Main program }
- program PREC4;
- {Program name: PREC4.p }
- {Function: This is the main module for this program. }
- {History: 6/10/89 Original by Prototyper. }
- { Created for MacTutor }
- { ©1989 CopyRight MacTutor All Rights Reserved }
-
- uses
- globals, About, Options, InitTheMenus, HandleTheMenus;
- var {Main variables}
- myEvent: EventRecord; {Event record for all events}
- doneFlag: boolean; {Exit program flag}
- code: integer; {Determine event type}
- whichWindow: WindowPtr; {See which window for event}
- tempRect, OldRect: Rect; {Rect for dragging}
- mResult: longint; {Menu list and item selected values}
- theMenu, theItem: integer;{Menu list and item selected}
- chCode: integer; {Key code}
- ch: char; {Key pressed in Ascii}
- theInput: TEHandle; {Used in text edit selections}
- myPt: Point; {Temp Point, used in Zoom}
-
-
- begin {Start of main body}
-
- MoreMasters; {This reserves space for more handles}
- InitGraf(@thePort); {Quickdraw Init}
- InitFonts; {Font manager init}
- InitWindows; {Window manager init}
- InitMenus; {Menu manager init}
- TEInit; {Text edit init}
- InitDialogs(nil); {Dialog manager}
-
- FlushEvents(everyEvent, 0);{Clear out all events}
- InitCursor; {Make an arrow cursor}
-
- doneFlag := FALSE; {Do not exit program yet}
-
- Init_My_Menus; {Initialize menu bar}
-
- theInput := nil; {Init to no text edit selection active}
- Init_Options; {Initialize the window routines}
- Open_Options(theInput); {Open the window routines at program start}
- D_About; {Open the modal dialog routines at program start}
- reply.fname := '';
- repeat {Start of main event loop}
- if (theInput <> nil) then{See if a TE is active}
- TEIdle(theInput); {Blink the cursor if everything is ok}
- SystemTask; {For support of desk accessories}
-
- if GetNextEvent(everyEvent, myEvent) then{If event then...}
- begin {Start handling the event}
- code := FindWindow(myEvent.where, whichWindow);{Get which window the event happened in}
-
-
- case myEvent.what of{Decide type of event}
- MouseDown: {Mouse button pressed}
- begin {Handle the pressed button}
- if (code = inMenuBar) then{See if a menu selection}
- begin{Get the menu selection and handle it}
- mResult := MenuSelect(myEvent.Where);{Do menu selection}
- theMenu := HiWord(mResult);{Get the menu list number}
- theItem := LoWord(mResult);{Get the menu list item number}
- Handle_My_Menu(doneFlag, theMenu, theItem, theInput);{Handle the menu}
- end;{End of inMenuBar}
-
- if (code = InDrag) then{See if in a window drag area}
- begin{Do dragging the window}
- tempRect := screenbits.bounds;{Get screen area, l,t,r,b, drag area}
- SetRect(tempRect, tempRect.Left + 10, tempRect.Top + 25, tempRect.Right - 10, tempRect.Bottom - 10);{}
- DragWindow(whichWindow, myEvent.where, tempRect);{Drag the window}
- end;{End of InDrag}
-
- if ((code = inGrow) and (whichWindow <> nil)) then{In a grow area of the window}
- begin{Handle the growing}
- SetPort(whichWindow);{Get ready to draw in this window}
-
- myPt := myEvent.where;{Get mouse position}
- GlobalToLocal(myPt);{Make it relative}
-
- OldRect := WhichWindow^.portRect;{Save the rect before resizing}
-
- with screenbits.bounds do{use the screens size}
- SetRect(tempRect, 15, 15, (right - left), (bottom - top) - 20);{l,t,r,b}
- mResult := GrowWindow(whichWindow, myEvent.where, tempRect);{Grow it}
- SizeWindow(whichWindow, LoWord(mResult), HiWord(mResult), TRUE);{Resize to result}
-
-
- SetPort(whichWindow);{Get ready to draw in this window}
-
- SetRect(tempRect, 0, myPt.v - 15, myPt.h + 15, myPt.v + 15); {Position for horz scrollbar area}
- EraseRect(tempRect);{Erase old area}
- InvalRect(tempRect);{Flag us to update it}
- SetRect(tempRect, myPt.h - 15, 0, myPt.h + 15, myPt.v + 15); {Position for vert scrollbar area}
- EraseRect(tempRect);{Erase old area}
- InvalRect(tempRect);{Flag us to update it}
- DrawGrowIcon(whichWindow);{Draw the grow Icon again}
- end;{End of doing the growing}
-
- if (code = inZoomIn) or (code = inZoomOut) then{Handle Zooming windows}
- begin{}
- if (WhichWindow <> nil) then{See if we have a legal window}
- begin{}
- SetPort(whichWindow);{Get ready to draw in this window}
-
- myPt := myEvent.where;{Get mouse position}
- GlobalToLocal(myPt);{Make it relative}
-
- OldRect := whichWindow^.portRect;{Save the rect before resizing}
-
- if TrackBox(whichWindow, myPt, code) then{Zoom it}
- begin{}
- ZoomWindow(WhichWindow, code, TRUE);{Resize to result}
- SetRect(tempRect, 0, 0, 32000, 32000);{l,t,r,b}
- EraseRect(tempRect);{Make sure we update the whole window effectively}
- InvalRect(tempRect);{Tell ourselves to update, redraw, the window contents}
- end;{}
- end;{}
- end;{}
-
- if (code = inGoAway) then{See if in a window goaway area}
- begin{Handle the goaway button}
- if TrackGoAway(whichWindow, myEvent.where) then{See if mouse released in GoAway box}
- begin{Handle the GoAway}
- case (GetWRefCon(whichWindow)) of{Do the appropiate window}
- 1:
- begin
- Close_Options(whichWindow, theInput);{Close this window}
- doneFlag := TRUE;
- end;
- otherwise{Handle others dialogs}
- begin{Others}
- end;{End of the otherwise}
- end;{End of the case}
- end;{End of TrackGoAway}
- end;{End of InGoAway}
-
- if (code = inContent) then{See if in a window}
- begin{Handle the hit inside a window}
- if (whichWindow <> FrontWindow) then{See if already selected or not, in front if selected}
- SelectWindow(whichWindow){Select this window to make it active}
- else{If already in front the already selected}
- begin{Handle the button in the content}
- SetPort(whichWindow);{Get ready to draw in this window}
- case (GetWRefCon(whichWindow)) of{Do the appropiate window}
- 1:
- Do_Options(myEvent, theInput);{Handle this window}
- otherwise{Handle others dialogs}
- begin{Others}
- end;{End of the otherwise}
- end;{End of the case}
- end;{End of else}
- end;{End of inContent}
-
- if (code = inSysWindow) then{See if a DA selection}
- SystemClick(myEvent, whichWindow);{Let other programs in}
-
- end; {End of MouseDown}
-
- KeyDown, AutoKey:{Handle key inputs}
- begin {Get the key and handle it}
- with myevent do{Check for menu command keys}
- begin{}
- chCode := BitAnd(message, CharCodeMask);{Get character}
- ch := CHR(chCode);{Change to ASCII}
- if (Odd(modifiers div CmdKey)) then{See if Command key is down}
- begin{}
- mResult := MenuKey(ch);{See if menu selection}
- theMenu := HiWord(mResult);{Get the menu list number}
- theItem := LoWord(mResult);{Get the menu item number}
- if (theMenu <> 0) then{See if a list was selected}
- Handle_My_Menu(doneFlag, theMenu, theItem, theInput);{Do the menu selection}
- if ((ch = 'x') or (ch = 'X')) and (theInput <> nil) then{}
- TECut(theInput);{Handle a Cut in a TE area}
- if ((ch = 'c') or (ch = 'C')) and (theInput <> nil) then{}
- TECopy(theInput);{Handle a Copy in a TE area}
- if ((ch = 'v') or (ch = 'V')) and (theInput <> nil) then{}
- TEPaste(theInput);{Handle a Paste in a TE area}
- end{}
- else if (theInput <> nil) then{}
- begin
- if ch = chr(9) then
- begin
- TEDeactivate(theInput);{Yes, so turn it off}
- if theInput = TitleFieldhndl then
- theInput := WidthFieldhndl
- else if theInput = WidthFieldhndl then
- theInput := HeightFieldhndl
- else if theInput = HeightFieldhndl then
- theInput := TitleFieldhndl;
- TEActivate(theInput);{Turn it on}
- recordstatus;
- end
- else
- TEKey(ch, theInput);{}
- end;
- end;{}
- end; {End for KeyDown,AutoKey}
-
- UpDateEvt: {Update event for a window}
- begin {Handle the update}
- whichWindow := WindowPtr(myEvent.message);{Get the window the update is for}
- BeginUpdate(whichWindow);{Set the clipping to the update area}
- case (GetWRefCon(whichWindow)) of{Do the appropiate window}
- 1:
- Update_Options(whichWindow);{Update this window}
- otherwise {Handle others dialogs}
- begin {Others}
- end; {End of the otherwise}
- end; {End of the case}
- EndUpdate(whichWindow);{Return to normal clipping area}
- end; {End of UpDateEvt}
-
- DiskEvt: {Disk inserted event}
- begin {Handle a disk event}
- if (HiWord(myevent.message) <> noErr) then{See if a diskette mount error}
- begin{due to unformatted diskette inserted}
- myEvent.where.h := ((screenbits.bounds.Right - screenbits.bounds.Left) div 2) - (304 div 2);{Center horz}
- myEvent.where.v := ((screenbits.bounds.Bottom - screenbits.bounds.Top) div 3) - (104 div 2);{Top 3ed vertically}
- InitCursor;{Make sure it has an arrow cursor}
- chCode := DIBadMount(myEvent.where, myevent.message);{Let the OS handle the diskette}
- end;{}
- end; {End of DiskEvt}
-
- app1Evt: {Check for events generated by this program}
- begin {Start handling our events}
- if (HiWord(myEvent.message) = 1) and (LoWord(myEvent.Message) = 1) then{See if OPEN event for this window ID}
- Open_Options(theInput);{Open the window}
- if (HiWord(myEvent.message) = 2) and (LoWord(myEvent.Message) = 1) then{See if CLOSE event for this window ID}
- Close_Options(WindowPtr(ord4(-1)), theInput);{Close the window}
- end; {End handling our events}
-
- ActivateEvt: {Window activated event}
- begin {Handle the activation}
- whichWindow := WindowPtr(myevent.message);{Get the window to be activated}
- if odd(myEvent.modifiers) then{Make sure it is Activate and not DeActivate}
- begin{Handle the activate}
- SelectWindow(whichWindow);{Activate the window by selecting it}
- end;{End of Activate}
- end; {End of ActivateEvt}
- otherwise {Used for debugging, to see what other events are coming in}
- end; {End of case}
- end; {end of GetNextEvent}
- until doneFlag; {End of the event loop}
-
- end. {End of the program}